package cn.edu.flow.security;

import cn.edu.flow.dao.UserInfoBeanMapper;
import cn.edu.flow.domain.UserInfoBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * security 查询用户service
 */
@Slf4j
@Component
public class FlowUserDetailsService implements UserDetailsService {

    @Autowired
    private UserInfoBeanMapper userInfoBeanMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        log.info("登录用户名：" + username);
       /* String passWord=passwordEncoder.encode("111");
        log.info("密码：" + passWord);
        return new User(username,passWord, AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_ACTIVITI_USER"));*/

        UserInfoBean userInfoBean = userInfoBeanMapper.selectByUsername(username);
        if (userInfoBean == null) {
            throw new UsernameNotFoundException("数据库中无此用户！");
        }
        return userInfoBean;

    }

}
